package org.lc.platform.redis.dto;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageDto implements Serializable {

    /**
     * 消息标题
     */
    private String title;

    /**
     * 消息内容
     */
    private String content;

    /**
     * 消息内容
     */
    private LocalDateTime createTime;


    public <T> T getContentByClz(Class<T> cls) {
        try {
            if (JSONUtil.isTypeJSONObject(this.content)) {
                return JSONUtil.toBean(JSONUtil.parseObj(this.content), cls);
            }
        } catch (Exception ignored) {
        }
        return null;
    }
}

